#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <algorithm> //reverse
#include <cmath>
using namespace std;

typedef struct STU
{
	int chinese;
	int math;
	int endlish;
	int totai;
	int id;
}STU;

bool compare(STU s1, STU s2)
{
	if (s1.totai != s2.totai)
		return s1.totai > s2.totai;
	else if (s1.chinese != s2.chinese)
		return s1.chinese > s2.chinese;
	else
		return s1.id < s2.id;
}
int main()
{
	STU arr[310];

	int N = 0;
	cin >> N;

	for (int i = 1; i <= N; i++)
	{
		cin >> arr[i].chinese >> arr[i].math >> arr[i].endlish;
		arr[i].totai = arr[i].chinese + arr[i].math + arr[i].endlish;
		arr[i].id = i;
	}
	sort(arr + 1, arr + 1 + N, compare);
	for (int i = 1; i <= 5; i++)
	{
		cout << arr[i].id << " " << arr[i].totai << endl;
	}
	return 0;
}